package com.ibm.android.decode;

import java.util.concurrent.CountDownLatch;

import android.os.Handler;
import android.os.Looper;

public class DecodeThread extends Thread {
	private Handler mDecodeHandler;
	private Handler mDecodeResultHandler;
	private final CountDownLatch mHandlerInitLatch;
	private int mPixelFormat;

	public DecodeThread(Handler decodeResultHandler, int pixelFormat) {
		mDecodeResultHandler = decodeResultHandler;
		mHandlerInitLatch = new CountDownLatch(1);
		mPixelFormat = pixelFormat;
	}

	public Handler getHandler() {
		try {
			mHandlerInitLatch.await();
		} catch (InterruptedException ie) {
			// continue?
		}
		return mDecodeHandler;
	}

	public void run() {
		Looper.prepare();
		mDecodeHandler = new DecodeHandler(mDecodeResultHandler, mPixelFormat);
		mHandlerInitLatch.countDown();
		Looper.loop();
	}
}
